package com.lc.afbx.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/6/12.
 */
@HttpInlet(Conn.INLET_API_MYORDER_RECOMMEND)
public class GetApiMyOrderRecommend extends BaseAsyGet<GetApiMyOrderRecommend.Info> {

    public String type, uid, starttime, endtime;

    public GetApiMyOrderRecommend(AsyCallBack<GetApiMyOrderRecommend.Info> asyCallBack) {
        super(asyCallBack);
    }


    protected Info parser(JSONObject jsonObject) {

        TOAST = jsonObject.optString("message");

        if (jsonObject.optInt("code") == 200) {

            JSONObject o = jsonObject.optJSONObject("data");
            Info info = new Info();

            JSONArray array = o.optJSONArray("alrecommend");

            if (array != null) {
                for (int i = 0; i < array.length(); i++) {

                    JSONObject object = array.optJSONObject(i);

                    Data d = new Data();
                    d.id = object.optString("id");
                    d.posttime = object.optString("posttime");
                    d.total = object.optString("total");
                    d.pstate = object.optString("pstate");
                    d.title = object.optString("title");
                    d.insurance_type = object.optString("insurance_type");
                    d.premium = object.optString("premium");

                    info.dataList.add(d);

                }
            }

            JSONArray array1 = o.optJSONArray("bcrecommend");

            if (array1 != null) {
                for (int i = 0; i < array1.length(); i++) {

                    JSONObject object = array1.optJSONObject(i);

                    Data d = new Data();
                    d.id = object.optString("id");
                    d.posttime = object.optString("posttime");
                    d.total = object.optString("total");
                    d.pstate = object.optString("pstate");
                    d.title = object.optString("title");
                    d.insurance_type = object.optString("insurance_type");
                    d.premium = object.optString("premium");

                    info.dataList.add(d);

                }
            }


            return info;

        }

        return null;
    }

    public static class Info {
        public List<Data> dataList = new ArrayList<>();
    }

    public static class Data {

        //        "id": "2",
//                "posttime": "2016-06-07 10:53:49",
//                "total": "1000.00",
//                "pstate": "2",
//                "title": "交强险"
//        "id": "3",
//                "posttime": "2016-06-08 09:22:30",
//                "insurance_type": "人身意外险",
//                "premium": "400.00",
//                "pstate": "1"
        public String id, posttime, total, pstate, title, insurance_type, premium;
    }


}
